# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gc
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=8.2.8
pkgrel=1
pkgdesc="A garbage collector for C and C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.hboehm.info/gc"
msys2_references=(
  "cpe: cpe:/a:bdwgc_project:bdwgc"
  "cpe: cpe:/a:boehm-demers-weiser:garbage_collector"
)
license=("MIT")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git"
         "${MINGW_PACKAGE_PREFIX}-libatomic_ops")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/ivmai/bdwgc/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('7649020621cb26325e1fb5c8742590d92fb48ce5c259b502faf7d9fb5dabb160')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  # autoreconf to get updated libtool files with clang support
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  CFLAGS+=" -fcommon" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-threads=posix \
    --disable-dependency-tracking \
    --enable-large-config \
    --enable-cplusplus \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
